import Vue from 'vue'
import index from './index.vue'
import axios from 'axios'
import store from './vuexText/startValues'
import router from './router/index'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import resource from 'vue-resource'
//import Router from "vue-router";
import Cookies from 'js-cookie'
Vue.config.productionTip = false
Vue.use(resource);

Vue.use(ElementUI);
router.beforeEach((to, from, next) => {
    store.state.activePathName=to.path;
    store.state.userMessage.accessToken=Cookies.get('accessToken');
    if(to.path != '/login'){
        if(Cookies.get('accessToken')&&Cookies.get('accessToken')==store.state.userMessage.accessToken){
            next();
        }else{
            next({
                name: 'login'
            })
        }
    }else{
        next();
    }
    next() // 必须使用 next ,执行效果依赖 next 方法的调用参数
})
new Vue({
    router,
    store,
    render: h => h(index),
}).$mount('#app')
axios.interceptors.request.use(function (config) { // 这里的config包含每次请求的内容
        if (store.getters.getToken) {
            config.headers['Content-Type'] = 'application/x-www-form-urlencoded'
        }
        return config
    },
    function(err) {
        return Promise.reject(err)
    })
